package demo;
import java.util.Scanner;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-07-18
 * Time: 18:57
 */



    public class test9 {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();

            int minSteps = findMinimumStepsToReachFibonacci(n);
            System.out.println(minSteps);
        }

        private static int findMinimumStepsToReachFibonacci(int n) {
            int a = 0;
            int b = 1;
            int num = 0;
            int minSteps = Integer.MAX_VALUE;

            while (num < n) {
                num = a + b;
                a = b;
                b = num;
                minSteps = Math.min(minSteps, n - num);
            }

            minSteps = Math.min(minSteps, num - n);

            return minSteps;
        }
    }

